package org.xtext.example.cr.validation;

import org.eclipse.emf.common.util.EList;
import org.eclipse.xtext.validation.Check;
import org.xtext.example.cr.cR.*;
import org.xtext.example.cr.cR.Number;

public class CRJavaValidator extends AbstractCRJavaValidator {

	@Check
	public void modelValidator(CRLanguage cr) {
		if (cr != null) {
			EList<Element> elementList = cr.getElements();
			if (elementList.size() < 1)
				error("Invalid argument!", CRPackage.Literals.CR_LANGUAGE__ELEMENTS);
		}
	}

	@Check
	public void elementValidator(Element e) {
		if (e.getVarDec() != null) {
			//
		} else if (e.getAssignment() != null) {
			//
		} else if (e.getArrayMethod() != null) {
			//
		} else if (e.getFunction() != null) {
			//
		}
	}
	
	@Check
	public void varDecValidator(VarDec vd) {
		if (vd.getPrimitiveDec() != null) {
			if (vd.getPrimitiveDec().getIntDec() != null) {
				for (SimpleVariable v : vd.getPrimitiveDec().getIntDec().getVars()) {
					v.setType("Int");
					v.setIsArray("false");
				}
			} else if (vd.getPrimitiveDec().getRealDec() != null) {
				for (SimpleVariable v : vd.getPrimitiveDec().getRealDec().getVars()) {
					v.setType("Real");
					v.setIsArray("false");
				}
			} else if (vd.getPrimitiveDec().getPartitionDec() != null) {
				for (SimpleVariable v : vd.getPrimitiveDec().getPartitionDec().getVars()) {
					v.setType("Partition");
					v.setIsArray("false");
				}
			}
		} else if (vd.getArrayDec() != null) {
			for (Variable v : vd.getArrayDec().getArrayVars()) {
				v.setType(vd.getArrayDec().getType());
			}
			for (Variable v : vd.getArrayDec().getArrayVars()) {
				v.setIsArray("true");
			}
			if (vd.getArrayDec().getRows() < 1) {
				for (Variable v : vd.getArrayDec().getArrayVars()) {
					v.setIsMatrix("false");
				}
			} else {
				for (Variable v : vd.getArrayDec().getArrayVars()) {
					v.setIsMatrix("true");
				}
			}
		}
	}

	@Check
	public void primitiveDecValidator(PrimitiveDec pd) {
		if (pd.getIntDec() != null) {
			//
		} else if (pd.getRealDec() != null) {
			//
		} else if (pd.getPartitionDec() != null) {
			//
		}
	}

	@Check
	public void intDecValidator(IntDec id) {
		EList<SimpleVariable> simpleVariableList = id.getVars();
		if (simpleVariableList.size() < 1)
			error("Missing variable!", CRPackage.Literals.INT_DEC__VARS);
	}

	@Check
	public void realDecValidator(RealDec rd) {
		EList<SimpleVariable> simpleVariableList = rd.getVars();
		if (simpleVariableList.size() < 1)
			error("Missing variable", CRPackage.Literals.REAL_DEC__VARS);
	}

	@Check
	public void partitionDecValidator(PartitionDec pd) {
		EList<SimpleVariable> simpleVariableList = pd.getVars();
		if (simpleVariableList.size() < 1)
			error("Missing variable!", CRPackage.Literals.PARTITION_DEC__VARS);
	}

	@Check
	public void arrayDecValidator(ArrayDec ad) {
		EList<Array> arrayList = ad.getArrayVars();
		if (arrayList.size() < 1)
			error("Missing variable!", CRPackage.Literals.ARRAY_DEC__ARRAY_VARS);
		else if (ad.getColums() < 0)
			error("Invalid colum number!", CRPackage.Literals.ARRAY_DEC__COLUMS);
	}
	
	@Check
	public void arrayElementValidator(ArrayElement ae) {
		if (ae.getArray().getIsMatrix().equals("false")) {
			if (ae.getIdx().getParam2() > 0 || ae.getIdx().getVar2() != null) {
				error("Vector index expected!", CRPackage.Literals.ARRAY_ELEMENT__IDX);
			}
		}
	}
	
	@Check
	public void indexValidator(Index i) {
		if (!i.getVar1().getType().equals("Int")) {
			error("Integer expected!", CRPackage.Literals.INDEX__VAR1);
		}
		if (!i.getVar2().getType().equals("Int")) {
			error("Integer expected!", CRPackage.Literals.INDEX__VAR2);
		}
	}
	
	@Check
	public void assignmentValidator(Assignment a) {
		
		String assignmentType = "";
		
		/* VARDEC ASSIGNMENT */
		
		if (a.getDec() != null) {
			if (a.getDec().getPrimitiveDec() != null) {
				if (a.getDec().getPrimitiveDec().getIntDec() != null) {
					assignmentType = "Int";
				} else if (a.getDec().getPrimitiveDec().getRealDec() != null) {
					assignmentType = "Real";
				} else if (a.getDec().getPrimitiveDec().getPartitionDec() != null) {
					assignmentType = "Partition";
				}
			} else if (a.getDec().getArrayDec() != null) {
				if (a.getDec().getArrayDec().getRows() > 0) {
					assignmentType = "Matrix" + a.getDec().getArrayDec().getType();
				} else {
					assignmentType = "Vector" + a.getDec().getArrayDec().getType();
				}
			}
		}
		
		/* VARIABLE ASSIGNMENT */
		
		else if (a.getVariables() != null && !a.getVariables().isEmpty()) {
			String firstType = a.getVariables().get(0).getType();
			String firstIsMatrix = a.getVariables().get(0).getIsMatrix();
			String firstIsArray = a.getVariables().get(0).getIsArray();
			for (Variable v : a.getVariables()) {
				if (!v.getType().equals(firstType)) {
					error("Unmatched types!", CRPackage.Literals.ASSIGNMENT__VARIABLES);
				}
			}
			if (firstIsArray.equals("true")) {
				if (firstIsMatrix.equals("true")) {
					assignmentType = "Matrix" + firstType;
				} else {
					assignmentType = "Vector" + firstType;
				}
			} else {
				assignmentType = firstType;
			}
		}
		
		/* ARRAY ELEMENT ASSIGNMENT */
		
		else if (a.getArrayElement() != null) {
			if (a.getArrayElement().getArray().getIsMatrix().equals("true")) {
				if (a.getArrayElement().getIdx().getParam2() > 0 || a.getArrayElement().getIdx().getVar2() != null) {
					assignmentType = a.getArrayElement().getArray().getType();
				} else {
					assignmentType = "Vector" + a.getArrayElement().getArray().getType();
				}
			} else {
				assignmentType = a.getArrayElement().getArray().getType();
			}
		}
		
		/* OTHERS */
		
		else {
			error("Invalid attribution!", CRPackage.Literals.ASSIGNMENT__DEC);
		}
		
		/* INT ASSIGNMENT */
		
		if (assignmentType.equals("Int")) {
			/* Number */
			if (a.getNumber() != null) {
				if (a.getNumber().getDecimal() > 0) {
					error("Integer expected!", CRPackage.Literals.ASSIGNMENT__NUMBER);
				}
			}
			/* Variable */
			else if (a.getVariable() != null) {
				if (a.getVariable().getType().equals("Int")) {
					if (a.getVariable().getIsArray().equals("true")) {
						error("Integer expected!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
					}
				} else {
					error("Integer expected!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
				}
			}
			/* Array Element */
			else if (a.getAssignedAE() != null) {
				if (!a.getAssignedAE().getArray().getType().equals("Int")) {
					error("Int expected!", CRPackage.Literals.ASSIGNMENT__ASSIGNED_AE);
				} else if (a.getAssignedAE().getArray().getIsMatrix().equals("true")) {
					if (a.getAssignedAE().getIdx().getParam2() < 1 && a.getAssignedAE().getIdx().getVar2() == null) {
						error("Int expected!", CRPackage.Literals.ASSIGNMENT__ASSIGNED_AE);
					}
				}
			}
			/* Others */
			else {
				error("Integer expected!", CRPackage.Literals.ASSIGNMENT__DEC);
			}
		}
		
		/* REAL ASSIGNMENT */
		
		else if (assignmentType.equals("Real")) {
			/* Number */
			if (a.getNumber() != null) {
				
			}
			/* CalcCR */
			else if (a.getCalcCR() != null) {
				/* Matrix */
				if (a.getCalcCR().getVector() == null) {
					error("Real expected!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
				}
				/* Vector - variable */
				else if (a.getCalcCR().getVar2() != null) {
					if (a.getCalcCR().getVar2().getIsArray().equals("true")) {
						error("Real expected!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
					} else {
						error("Real expected!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
					}
				}
				/* Vector - array element */
				else if (a.getCalcCR().getArrayElement2() != null) {
					if (a.getCalcCR().getArrayElement2().getArray().getIsMatrix().equals("true")) {
						error("Real expected!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
					} else {
						error("Real expected!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
					}
				}
			}
			/* CalcMean */
			else if (a.getCalcMean() != null) {
				if (a.getCalcMean().getArray() != null) {
					if (a.getCalcMean().getArray().getIsMatrix().equals("true")) {
						error("Real expected!", CRPackage.Literals.ASSIGNMENT__CALC_MEAN);
					}
				} else if (a.getCalcMean().getCalcCR() != null) {
					if (a.getCalcMean().getCalcCR().getArrayElement()!= null || a.getCalcMean().getCalcCR().getVector()!= null) {
						error("Real expected!", CRPackage.Literals.ASSIGNMENT__CALC_MEAN);
					}
				}
			}
			/* Variable */
			else if (a.getVariable() != null) {
				if (a.getVariable().getType().equals("Real") || a.getVariable().getType().equals("Int")) {
					if (a.getVariable().getIsArray().equals("true")) {
						error("Real expected!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
					}
				} else {
					error("Real expected!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
				}
			}
			/* Array Element */
			else if (a.getAssignedAE() != null) {
				if (!a.getAssignedAE().getArray().getType().equals("Real")) {
					error("Real expected!", CRPackage.Literals.ASSIGNMENT__ASSIGNED_AE);
				} else if (a.getAssignedAE().getArray().getIsMatrix().equals("true")) {
					if (a.getAssignedAE().getIdx().getParam2() < 1 && a.getAssignedAE().getIdx().getVar2() == null) {
						error("Real expected!", CRPackage.Literals.ASSIGNMENT__ASSIGNED_AE);
					}
				}
			}
			/* Others */
			else {
				error("Real expected!", CRPackage.Literals.ASSIGNMENT__DEC);
			}
		}
		
		/* PARTITION ASSIGNMENT */
		
		else if (assignmentType.equals("Partition")) {
			/* Archive */
			if (a.getArchive() != null) {
				//
			}
			/* Variable */
			else if (a.getVariable() != null) {
				if (a.getVariable().getType().equals("Partition")) {
					if (a.getVariable().getIsArray().equals("true")) {
						error("Partition expected!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
					}
				} else {
					error("Partition expected!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
				}
			}
			/* Array Element */
			else if (a.getAssignedAE() != null) {
				if (!a.getAssignedAE().getArray().getType().equals("Partition")) {
					error("Partition expected!", CRPackage.Literals.ASSIGNMENT__ASSIGNED_AE);
				} else if (a.getAssignedAE().getArray().getIsMatrix().equals("true")) {
					if (a.getAssignedAE().getIdx().getParam2() < 1 && a.getAssignedAE().getIdx().getVar2() == null) {
						error("Partition expected!", CRPackage.Literals.ASSIGNMENT__ASSIGNED_AE);
					}
				}
			}
			/* Others */
			else {
				error("Partition expected!", CRPackage.Literals.ASSIGNMENT__DEC);
			}
		} 
		
		/* VECTOR ASSIGNMENT */
		
		else if (assignmentType.contains("Vector")) {
			/* Variable */
			if (a.getVariable() != null) {
				if (a.getVariable().getType().equals("Int") && assignmentType.contains("Int")) {
					if (a.getVariable().getIsArray().equals("false")) {
						error("Vector of integer expected!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
					}
				} else if ((a.getVariable().getType().equals("Real") || a.getVariable().getType().equals("Int")) && assignmentType.contains("Real")) {
					if (a.getVariable().getIsArray().equals("false")) {
						error("Vector of real expected!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
					}
				} else if (a.getVariable().getType().equals("Partition") && assignmentType.contains("Partition")) {
					if (a.getVariable().getIsArray().equals("false")) {
						error("Vector of partion expected!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
					}
				} else {
					error("Unmatched types!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
				}
			}
			/* Array Element */
			else if (a.getAssignedAE() != null) {
				if (!assignmentType.contains(a.getAssignedAE().getArray().getType())) {
					error("Unmatched types!", CRPackage.Literals.ASSIGNMENT__ASSIGNED_AE);
				} else if (a.getAssignedAE().getArray().getIsMatrix().equals("true")) {
					if (a.getAssignedAE().getIdx().getParam2() > 0 || a.getAssignedAE().getIdx().getVar2() != null) {
						error("Vector of" + a.getAssignedAE().getArray().getType() + "expected!", CRPackage.Literals.ASSIGNMENT__ASSIGNED_AE);
					}
				}
			}
			/* CalcCR */
			else if (a.getCalcCR() != null) {
				if (assignmentType.contains("Real")) {
					/* Matrix */
					if (a.getCalcCR().getVector() == null) {
						error("Vector of real expected!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
					}
					/* Vector - variable */
					else if (a.getCalcCR().getVar2() != null) {
						if (a.getCalcCR().getVar2().getIsArray().equals("true")) {
							if (a.getCalcCR().getVar2().getIsMatrix().equals("true")) {
								error("Vector of real expected!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
							}
						} else {
							error("Vector of real expected!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
						}
					}
					/* Vector - array element */
					else if (a.getCalcCR().getArrayElement2() != null) {
						if (a.getCalcCR().getArrayElement2().getArray().getIsMatrix().equals("false") ||
							a.getCalcCR().getArrayElement2().getIdx().getParam2() > 0 ||
							a.getCalcCR().getArrayElement2().getIdx().getVar2() != null) {
							error("Vector of real expected!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
						}
					}
				} else {
					error("Unmatched types!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
				}
			}
			/* CalcMean */
			else if (a.getCalcMean() != null) {
				if (assignmentType.contains("Real")) {
					if (a.getCalcMean().getArray() != null) {
						if (a.getCalcMean().getArray().getIsMatrix().equals("false")) {
							error("Vector of real expected!", CRPackage.Literals.ASSIGNMENT__CALC_MEAN);
						}
					} else if (a.getCalcMean().getCalcCR() != null) {
						if (a.getCalcMean().getCalcCR().getArrayElement()== null && a.getCalcMean().getCalcCR().getVector()== null) {
							error("Vector of real expected!", CRPackage.Literals.ASSIGNMENT__CALC_MEAN);
						}
					}
				} else {
					error("Unmatched types!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
				}
			}
			/* Others */
			else {
				error("Vector expected!", CRPackage.Literals.ASSIGNMENT__DEC);
			}
		}
		
		/* MATRIX ASSIGNMENT */
		
		else if (assignmentType.contains("Matrix")) {
			/* Variable */
			if (a.getVariable() != null) {
				if (a.getVariable().getType().equals("Int") && assignmentType.contains("Int")) {
					if (a.getVariable().getIsMatrix().equals("false")) {
						error("Matrix of integer expected!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
					}
				} else if ((a.getVariable().getType().equals("Real") || a.getVariable().getType().equals("Int")) && assignmentType.contains("Real")) {
					if (a.getVariable().getIsMatrix().equals("false")) {
						error("Matrix of real expected!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
					}
				} else if (a.getVariable().getType().equals("Partition") && assignmentType.contains("Partition")) {
					if (a.getVariable().getIsMatrix().equals("false")) {
						error("Matrix of partion expected!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
					}
				} else {
					error("Unmatched types!", CRPackage.Literals.ASSIGNMENT__VARIABLE);
				}
			}
			/* CalcCR */
			else if (a.getCalcCR() != null) {
				if (assignmentType.contains("Real")) {
					/* Matrix */
					if (a.getCalcCR().getVector() != null) {
						//
					}
					/* Vector */
					else {
						error("Matrix of real expected!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
					}
				} else {
					error("Unmatched types!", CRPackage.Literals.ASSIGNMENT__CALC_CR);
				}
			}
			/* Others */
			else {
				error("Matrix expected!", CRPackage.Literals.ASSIGNMENT__DEC);
			}
		}
		
		/* OTHERS */
		
		else {
			error("Invalid attribution!", CRPackage.Literals.ASSIGNMENT__DEC);
		}
	}

	@Check
	public void sizeValidator(Size s) {
		/* array variable */
		if (s.getArray() != null) {
			//
		}
		/* array element */
		else {
			if (s.getArrayElement().getArray().getIsMatrix().equals("true")) {
				if (s.getArrayElement().getIdx().getParam2() > 0 || s.getArrayElement().getIdx().getVar2() != null) {
					error("Array expected!", CRPackage.Literals.SIZE__ARRAY_ELEMENT);
				}
			} else {
				error("Array expected!", CRPackage.Literals.SIZE__ARRAY_ELEMENT);
			}
		}
	}
	
	@Check
	public void addValidator(Add a) {
		
		String type;
		/* array variable */
		if (a.getArray() != null) {
			type = a.getArray().getType();
		}
		/* array element */
		else {
			if (a.getArrayElement().getArray().getIsMatrix().equals("true")) {
				if (a.getArrayElement().getIdx().getParam2() > 0 || a.getArrayElement().getIdx().getVar2() != null) {
					error("Array expected!", CRPackage.Literals.ADD__ARRAY_ELEMENT);
				}
			} else {
				error("Array expected!", CRPackage.Literals.ADD__ARRAY_ELEMENT);
			}
			type = a.getArrayElement().getArray().getType();
		}
		
		if (type.equals("Int")) {
			/* Numbers */
			if (a.getNumParams() != null) {
				for (Number n : a.getNumParams()) {
					if (n.getDecimal() > 0) {
						error("Integer expected!", CRPackage.Literals.ADD__NUM_PARAMS);
					}
				}
			}
			/* Variables */
			if (a.getVarParams() != null) {
				for (Variable v : a.getVarParams()) {
					if (!v.getType().equals(type)) {
						error("Integer expected!", CRPackage.Literals.ADD__VAR_PARAMS);
					}
				}
			}
			/* Array Elements */
			if (a.getAeParams() != null) {
				for (ArrayElement ae: a.getAeParams()) {
					if (!ae.getArray().getType().equals(type)) {
						error("Integer expected!", CRPackage.Literals.ADD__AE_PARAMS);
					}
				}
			}
			/* Archives */
			if (a.getArchive() != null) {
				error("Integer expected!", CRPackage.Literals.ADD__ARCHIVE);
			}
			/* Sizes */
			if (a.getSizes() != null) {
				//
			}
			/* CalcCRs */
			if (a.getCalcCRs() != null) {
				error("Integer expected!", CRPackage.Literals.ADD__CALC_CRS);
			}
			/* CalcMeans */
			if (a.getCalcMeans() != null) {
				error("Integer expected!", CRPackage.Literals.ADD__CALC_MEANS);
			}
		} else if (type.equals("Real")) {
			/* Numbers */
			if (a.getNumParams() != null) {
				//
			}
			/* Variables */
			if (a.getVarParams() != null) {
				for (Variable v : a.getVarParams()) {
					if (!v.getType().equals(type) && !v.getType().equals("Int")) {
						error("Real expected!", CRPackage.Literals.ADD__VAR_PARAMS);
					}
				}
			}
			/* Array Elements */
			if (a.getAeParams() != null) {
				for (ArrayElement ae: a.getAeParams()) {
					if (!ae.getArray().getType().equals(type) && !ae.getArray().getType().equals("Int")) {
						error("Real expected!", CRPackage.Literals.ADD__AE_PARAMS);
					}
				}
			}
			/* Archives */
			if (a.getArchive() != null) {
				error("Real expected!", CRPackage.Literals.ADD__ARCHIVE);
			}
			/* Sizes */
			if (a.getSizes() != null) {
				//
			}
			/* CalcCRs */
			if (a.getCalcCRs() != null) {
				//
			}
			/* CalcMeans */
			if (a.getCalcMeans() != null) {
				//
			}
		} else if (type.equals("Partition")) {
			/* Numbers */
			if (a.getNumParams() != null) {
				error("Partition expected!", CRPackage.Literals.ADD__NUM_PARAMS);
			}
			/* Variables */
			if (a.getVarParams() != null) {
				for (Variable v : a.getVarParams()) {
					if (!v.getType().equals(type)) {
						error("Partition expected!", CRPackage.Literals.ADD__VAR_PARAMS);
					}
				}
			}
			/* Array Elements */
			if (a.getAeParams() != null) {
				for (ArrayElement ae: a.getAeParams()) {
					if (!ae.getArray().getType().equals(type)) {
						error("Partition expected!", CRPackage.Literals.ADD__AE_PARAMS);
					}
				}
			}
			/* Archives */
			if (a.getArchive() != null) {
				//
			}
			/* Sizes */
			if (a.getSizes() != null) {
				error("Partition expected!", CRPackage.Literals.ADD__SIZES);
			}
			/* CalcCRs */
			if (a.getCalcCRs() != null) {
				error("Partition expected!", CRPackage.Literals.ADD__CALC_CRS);
			}
			/* CalcMeans */
			if (a.getCalcMeans() != null) {
				error("Partition expected!", CRPackage.Literals.ADD__CALC_MEANS);
			}
		}
		
		
	}
	
	@Check
	public void deleteValidator (Delete d) {
		/* array variable */
		if (d.getArray() != null) {
			//
		}
		/* array element */
		else {
			if (d.getArrayElement().getArray().getIsMatrix().equals("true")) {
				if (d.getArrayElement().getIdx().getParam2() > 0 || d.getArrayElement().getIdx().getVar2() != null) {
					error("Array expected!", CRPackage.Literals.DELETE__ARRAY_ELEMENT);
				}
			} else {
				error("Array expected!", CRPackage.Literals.DELETE__ARRAY_ELEMENT);
			}
		}
		
		/* Variables */
		if (d.getDelVars() != null) {
			for (Variable v : d.getDelVars()) {
				if (!v.getType().equals("Int")) {
					error("Integer expected!", CRPackage.Literals.DELETE__DEL_VARS);
				}
			}
		}
		/* ArrayElement */
		if (d.getDelArrays() != null) {
			for (ArrayElement ae : d.getDelArrays()) {
				if (!ae.getArray().getType().equals("Int")) {
					error("Integer expected!", CRPackage.Literals.DELETE__DEL_VARS);
				}
			}
		}
	}

	@Check
	public void forValidator (For f) {
		if (f.getLocVar() != null) {
			if (!f.getLocVar().getType().equals("Partition")) {
				error("Partition expected!", CRPackage.Literals.FOR__LOC_VAR);
			}
		}
	}
	
	@Check
	public void forallValidator (Forall f) {
		if (f.getLocVar() != null) {
			if (!f.getLocVar().getType().equals("Int")) {
				error("Integer expected!", CRPackage.Literals.FORALL__LOC_VAR);
			}
		}
		
		/* Begin Variable */
		if (f.getBeginVar() != null) {
			if (!f.getBeginVar().getType().equals("Int")) {
				error("Integer expected!", CRPackage.Literals.FORALL__BEGIN_VAR);
			}
		}
		/* Begin Array Element */
		else if (f.getBeginAE() != null) {
			if (!f.getBeginAE().getArray().getType().equals("Int")) {
				error("Integer expected!", CRPackage.Literals.FORALL__BEGIN_VAR);
			} else {
				if (f.getBeginAE().getArray().getIsMatrix().equals("true") && f.getBeginAE().getIdx().getParam2() < 1 && f.getBeginAE().getIdx().getVar2() == null) {
					error("Integer expected!", CRPackage.Literals.FORALL__BEGIN_AE);
				}
			}
		}
		
		/* End Variable */
		if (f.getEndVar() != null) {
			if (!f.getEndVar().getType().equals("Int")) {
				error("Integer expected!", CRPackage.Literals.FORALL__END_VAR);
			}
		}
		/* End Array Element */
		else if (f.getEndAE() != null) {
			if (!f.getEndAE().getArray().getType().equals("Int")) {
				error("Integer expected!", CRPackage.Literals.FORALL__END_VAR);
			} else {
				if (f.getEndAE().getArray().getIsMatrix().equals("true") && f.getEndAE().getIdx().getParam2() < 1 && f.getEndAE().getIdx().getVar2() == null) {
					error("Integer expected!", CRPackage.Literals.FORALL__END_AE);
				}
			}
		}
	}

	@Check
	public void calcCRValidator (CalcCR c) {
		/* Vector */
		if (c.getVector() != null) {
			if (c.getVector().getIsMatrix().equals("true")) {
				error("Vector of partition expected!", CRPackage.Literals.CALC_CR__VECTOR);
			}
			if (!c.getVector().getType().equals("Partition")) {
				error("Vector of partition expected!", CRPackage.Literals.CALC_CR__VECTOR);
			}
		} else if (c.getArrayElement() != null) {
			if (!c.getArrayElement().getArray().getType().equals("Partition")) {
				error("Vector of partition expected!", CRPackage.Literals.CALC_CR__ARRAY_ELEMENT);
			}
			if (c.getArrayElement().getArray().getIsMatrix().equals("false")) {
				error("Vector of partition expected!", CRPackage.Literals.CALC_CR__ARRAY_ELEMENT);
			}
		}
		
		/* Array Element */
		if (c.getArrayElement1() != null) {
			if (!c.getArrayElement1().getArray().getType().equals("Partition")) {
				error("Partition expected!", CRPackage.Literals.CALC_CR__ARRAY_ELEMENT1);
			}
			if (c.getArrayElement1().getArray().getIsMatrix().equals("true") && c.getArrayElement1().getIdx().getParam2() < 1 && c.getArrayElement1().getIdx().getVar2() == null) {
				error("Partition expected!", CRPackage.Literals.CALC_CR__ARRAY_ELEMENT1);
			}
		}
		if (c.getArrayElement2() != null) {
			if (!c.getArrayElement2().getArray().getType().equals("Partition")) {
				error("Partition or vector of partition expected!", CRPackage.Literals.CALC_CR__ARRAY_ELEMENT2);
			}
		}
		/* Variable */
		if (c.getVar1() != null) {
			if (!c.getVar1().getType().equals("Partition")) {
				error("Partition expected!", CRPackage.Literals.CALC_CR__VAR1);
			}
		}
		if (c.getVar2() != null) {
			if (!c.getVar2().getType().equals("Partition")) {
				error("Partition or vector of partition expected!", CRPackage.Literals.CALC_CR__VAR2);
			}
			if (c.getVar2().getIsMatrix().equals("true")) {
				error("Partition or vector of partition expected!", CRPackage.Literals.CALC_CR__VAR2);
			}
		}
	}
	
	@Check
	public void calcMeanValidator(CalcMean cm) {
		/* Vector or Matrix */
		if (cm.getArray() != null) {
			if (!cm.getArray().getType().equals("Real")) {
				error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__ARRAY);
			}
		}
		/* Array Element */
		else if (cm.getArrayElement() != null) {
			if (!cm.getArrayElement().getArray().getType().equals("Real")) {
				error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__ARRAY_ELEMENT);
			}
			if (cm.getArrayElement().getArray().getIsMatrix().equals("true")) {
				if (cm.getArrayElement().getIdx().getParam2() < 1 || cm.getArrayElement().getIdx().getVar2() == null) {
					error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__ARRAY_ELEMENT);
				}
			} else {
				error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__ARRAY_ELEMENT);
			}
		}
		/* CalcCR */
		else if (cm.getCalcCR() != null) {
			/* Array Element 2*/
			if (cm.getCalcCR().getArrayElement2() != null) {
				if (cm.getCalcCR().getArrayElement2().getArray().getIsMatrix().equals("true")) {
					if (cm.getCalcCR().getArrayElement2().getIdx().getParam2() > 0 || cm.getCalcCR().getArrayElement2().getIdx().getVar2() != null) {
						error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__CALC_CR);
					}
				} else {
					error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__CALC_CR);
				}
			} 
			/* Variable 2 */
			else if (cm.getCalcCR().getVar2().getIsArray().equals("false")) {
				error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__CALC_CR);
			}
		}
	}
	
	@Check
	public void highestCRValidator(HighestCR h) {
		/* Vector or Matrix */
		if (h.getArray() != null) {
			if (!h.getArray().getType().equals("Real")) {
				error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__ARRAY);
			}
		}
		/* Array Element */
		else if (h.getArrayElement() != null) {
			if (!h.getArrayElement().getArray().getType().equals("Real")) {
				error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__ARRAY_ELEMENT);
			}
			if (h.getArrayElement().getArray().getIsMatrix().equals("true")) {
				if (h.getArrayElement().getIdx().getParam2() < 1 || h.getArrayElement().getIdx().getVar2() == null) {
					error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__ARRAY_ELEMENT);
				}
			} else {
				error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__ARRAY_ELEMENT);
			}
		}
		/* CalcCR */
		else if (h.getCalcCR() != null) {
			/* Array Element 2*/
			if (h.getCalcCR().getArrayElement2() != null) {
				if (h.getCalcCR().getArrayElement2().getArray().getIsMatrix().equals("true")) {
					if (h.getCalcCR().getArrayElement2().getIdx().getParam2() > 0 || h.getCalcCR().getArrayElement2().getIdx().getVar2() != null) {
						error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__CALC_CR);
					}
				} else {
					error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__CALC_CR);
				}
			} 
			/* Variable 2 */
			else if (h.getCalcCR().getVar2().getIsArray().equals("false")) {
				error("Vector or matrix of real expected!", CRPackage.Literals.CALC_MEAN__CALC_CR);
			}
		}
	}
	
	@Check
	public void findSimilarValidator(FindSimilar fs) {
		/* Vector or Matrix */
		if (fs.getMatrix() != null) {
			if (!fs.getMatrix().getIsMatrix().equals("false")) {
				error("Matrix of partition expected!", CRPackage.Literals.FIND_SIMILAR__MATRIX);
			}
		}
		
		/* Variable */
		if (fs.getIndxVar() != null) {
			if (!fs.getIndxVar().getType().equals("Int")) {
				error("Integer expected!", CRPackage.Literals.FIND_SIMILAR__INDX_VAR);
			}
		}
		/* Array Element */
		else if (fs.getIndxAE() != null) {
			if (!fs.getIndxAE().getArray().getType().equals("Int")) {
				error("Integer expected!", CRPackage.Literals.FIND_SIMILAR__INDX_AE);
			} else if (fs.getIndxAE().getArray().getIsMatrix().equals("true")) {
				if (fs.getIndxAE().getIdx().getParam2() < 1 && fs.getIndxAE().getIdx().getVar2() != null) {
					error("Integer expected!", CRPackage.Literals.FIND_SIMILAR__INDX_AE);
				}
			}
		}
		
		/* Similarity Variable */
		if (fs.getSimilarityVar() != null) {
			if (!fs.getSimilarityVar().getType().equals("Int") && !fs.getSimilarityVar().getType().equals("Real")) {
				error("Real expected!", CRPackage.Literals.FIND_SIMILAR__SIMILARITY_VAR);
			}
		}
		/* Similarity Array Element */
		else if (fs.getSimilarityAE() != null) {
			if (!fs.getSimilarityAE().getArray().getType().equals("Int") && !fs.getSimilarityAE().getArray().getType().equals("Real")) {
				error("Real expected!", CRPackage.Literals.FIND_SIMILAR__SIMILARITY_AE);
			} else if (fs.getSimilarityAE().getArray().getIsMatrix().equals("true")) {
				if (fs.getSimilarityAE().getIdx().getParam2() < 1 && fs.getSimilarityAE().getIdx().getVar2() == null) {
					error("Real expected!", CRPackage.Literals.FIND_SIMILAR__SIMILARITY_AE);
				}
			}
		}
		/* Similarity CalcCR */
		else if (fs.getSimilarityCalcCR() != null) {
			/* Matrix */
			if (fs.getSimilarityCalcCR().getVector() == null) {
				error("Real expected!", CRPackage.Literals.FIND_SIMILAR__SIMILARITY_CALC_CR);
			}
			/* Vector - variable */
			else if (fs.getSimilarityCalcCR().getVar2() != null) {
				if (fs.getSimilarityCalcCR().getVar2().getIsArray().equals("true")) {
					error("Real expected!", CRPackage.Literals.FIND_SIMILAR__SIMILARITY_CALC_CR);
				} else {
					error("Real expected!", CRPackage.Literals.FIND_SIMILAR__SIMILARITY_CALC_CR);
				}
			}
			/* Vector - array element */
			else if (fs.getSimilarityCalcCR().getArrayElement2() != null) {
				if (fs.getSimilarityCalcCR().getArrayElement2().getArray().getIsMatrix().equals("true")) {
					error("Real expected!", CRPackage.Literals.FIND_SIMILAR__SIMILARITY_CALC_CR);
				} else {
					error("Real expected!", CRPackage.Literals.FIND_SIMILAR__SIMILARITY_CALC_CR);
				}
			}
		}
		/* Similarity CalcMean */
		else if (fs.getSimilarityCalcMean() != null) {
			if (fs.getSimilarityCalcMean().getArray() != null) {
				if (fs.getSimilarityCalcMean().getArray().getIsMatrix().equals("true")) {
					error("Real expected!", CRPackage.Literals.FIND_SIMILAR__SIMILARITY_CALC_MEAN);
				}
			} else if (fs.getSimilarityCalcMean().getCalcCR() != null) {
				if (fs.getSimilarityCalcMean().getCalcCR().getArrayElement()!= null || fs.getSimilarityCalcMean().getCalcCR().getVector()!= null) {
					error("Real expected!", CRPackage.Literals.FIND_SIMILAR__SIMILARITY_CALC_MEAN);
				}
			}
		}
		
	}
	
	
	
}
